<template>
  <el-form ref="searchForm" :model="searchForm" label-width="120px">
    <el-row v-if="conditionCount > 0">
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="模板标题" prop="templateTitle" label-for="templateTitle">
          <el-input
            v-model="searchForm.templateTitle"
            element-id="templateTitle"
            placeholder="请输入模板标题"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="物流公司" prop="expressCompany" label-for="expressCompany">
          <el-input
            v-model="searchForm.expressCompany"
            element-id="expressCompany"
            placeholder="请输入物流公司"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="省收货地" prop="province" label-for="province">
          <el-input
            v-model="searchForm.province"
            element-id="province"
            placeholder="请输入省收货地"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-button
          type="primary"
          style="margin-left: 10px;"
          :loading="loading.search"
          @click="handleSubmit"
        >搜索</el-button>
        <el-button @click="handleReset">重置</el-button>
        <a v-if="conditionCount > 3" style="margin-left: 10px;" @click="collapse = !collapse">
          <el-button type="text" v-if="!collapse">
            展开
            <svg-icon icon-class="ios-arrow-down" />
          </el-button>
          <el-button v-else type="text">
            收起
            <svg-icon icon-class="ios-arrow-up" />
          </el-button>
        </a>
      </el-col>
    </el-row>
    <el-row v-if="collapse">
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="市收货地" prop="city" label-for="city">
          <el-input
            v-model="searchForm.city"
            element-id="city"
            placeholder="请输入市收货地"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="区县收货地" prop="district" label-for="district">
          <el-input
            v-model="searchForm.district"
            element-id="district"
            placeholder="请输入区县收货地"
            clearable
            @keyup.enter.native="handleSubmit"
          />
        </el-form-item>
      </el-col>
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="是否包邮" prop="expressFree">
          <el-select
            v-model="searchForm.expressFree"
            placeholder="请选择是否包邮"
            clearable
            style="width: 100%;"
            @change="handleSubmit"
          >
            <el-option
              v-for="item in selects.expressFreeSelect"
              :value="item.value"
              :key="item.value"
              :label="item.displayValue"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script>
import * as utils from '@/utils/utils'
import * as ResponseStatus from '@/utils/response-status'
export default {
  name: 'ExpressTemplateItemSearchQuick',
  data() {
    return {
      loading: {
        search: false,
      },
      conditionCount: 6,
      collapse: false,
      searchForm: {
        pageNo: 1,
        pageSize: 10,
        sortColumn: undefined,
        sortOrder: undefined,
        id: undefined,
        idMin: undefined,
        idMax: undefined,
        templateId: undefined,
        templateIdMin: undefined,
        templateIdMax: undefined,
        templateTitle: undefined,
        templateIsActive: undefined,
        templateIsActiveMin: undefined,
        templateIsActiveMax: undefined,
        expressCompany: undefined,
        province: undefined,
        city: undefined,
        district: undefined,
        expressFree: undefined,
        expressFreeMin: undefined,
        expressFreeMax: undefined,
        expressFee: undefined,
        expressFeeMin: undefined,
        expressFeeMax: undefined,
        expressSpec: undefined,
        expressSpecMin: undefined,
        expressSpecMax: undefined,
        incrementSpec: undefined,
        incrementSpecMin: undefined,
        incrementSpecMax: undefined,
        incrementFee: undefined,
        incrementFeeMin: undefined,
        incrementFeeMax: undefined,
        freeCondition: undefined,
        freeConditionMin: undefined,
        freeConditionMax: undefined,
        freeMaxPayment: undefined,
        freeMaxPaymentMin: undefined,
        freeMaxPaymentMax: undefined,
        version: undefined,
        versionMin: undefined,
        versionMax: undefined,
        createTime: undefined,
        createTimeMin: undefined,
        createTimeMax: undefined,
        updateTime: undefined,
        updateTimeMin: undefined,
        updateTimeMax: undefined,
        isActive: undefined,
      },
      dataDictCodes: ['YES_NO'],
      selects: {
        templateIsActiveSelect: [],
        expressFreeSelect: [],
        isActiveSelect: [],
      },
    }
  },
  computed: {},
  mounted() {
    this.initDataDict()
  },
  methods: {
    initDataDict() {
      utils
        .getDataDict(this.dataDictCodes)
        .then((response) => {
          if (response) {
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'templateIsActive',
              dataProp: 'templateIsActiveSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'expressFree',
              dataProp: 'expressFreeSelect',
            })
            utils.getSelectDictItems({
              mainComponent: this,
              dataDictItems: response,
              dictCode: 'YES_NO',
              formProp: 'isActive',
              dataProp: 'isActiveSelect',
            })
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    resetForm(excludeProps) {
      for (let key in this.searchForm) {
        if (excludeProps && excludeProps.includes(key)) {
          continue
        }
        this.searchForm[key] = undefined
      }
    },
    handleSubmit() {
      this.$emit('quickSearch')
    },
    handleReset() {
      this.$emit('researchTable')
    },
  },
}
</script>
<style>
.ivu-quick-opt {
  text-align: right;
}
</style>